# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
#   cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
#   Mayor.create(:name => 'Daley', :city => cities.first)
Dept::Storefront.create!([
  {
    :name => '居然之家1号店',
    :link_phone => '1397611111',
    :link_man => '小庄',
    :address => '海口居然之家'
  },
  {
    :name => '华森1号店',
    :link_phone => '1397611111',
    :link_man => '小庄',
    :address => '海口居然之家'
  },
  {
    :name => '华森2号店',
    :link_phone => '1397611111',
    :link_man => '小庄',
    :address => '海口居然之家'
  }
])

Dept::Storehouse.create!([
  {
    :name => '1号仓库',
    :link_phone => '1397611111',
    :link_man => '小庄',
    :address => '丘海大道11号半山花园海天阁1688'
  },
  {
    :name => '2号仓库',
    :link_phone => '1397611111',
    :link_man => '小庄',
    :address => '丘海大道11号半山花园海天阁1688'
  },
  {
    :name => '3号仓库',
    :link_phone => '1397611111',
    :link_man => '小庄',
    :address => '丘海大道11号半山花园海天阁1688'
  }
])

Employee.create! [ { 
   :full_name => '小张',
   :sex => 'man',
   :mobile => '13987777777',
   :address => '海口市金贸中路1号半山花园海天阁1688'
 }, { 
   :full_name => '小陈',
   :sex => 'woman',
   :mobile => '13987777777',
   :address => '海口市金贸中路1号半山花园海天阁1788'
 },{ 
   :full_name => '小李',
   :sex => 'unknown',
   :mobile => '13987777777',
   :address => '海口市金贸中路1号半山花园海天阁1888'
 }
]

Thread.current[:current_employee_id] = Employee.last.id

Buyer.create! [ { 
   :full_name => '刘总',
   :sex => 'man',
   :mobile => '13987777777',
   :link_phone => '1123',
   :address => '海口市金贸中路1号半山花园海天阁1888'
 }, { 
   :full_name => '王总',
   :sex => 'woman',
   :mobile => '13987777777',
   :address => '海口市金贸中路1号半山花园海天阁1888'
 },{ 
   :full_name => '张总',
   :sex => 'unknown',
   :mobile => '13987777777',
   :address => '海口市金贸中路1号半山花园海天阁1888'
 }
]

Factory.create!([
  {
    :name => '星期六家具厂',
    :link_phone => '1397611111',
    :link_man => '小庄',
    :address => '丘海大道11号',
    :email => 'a@gmail.com',
    :qq => '7888888',
    :msn => 'aa@hotmail.com'
  },
  {
    :name => '皇朝家私厂',
    :link_phone => '1397611111',
    :link_man => '小庄',
    :address => '丘海大道11号',
    :email => 'a@gmail.com',
    :qq => '7888888',
    :msn => 'aa@hotmail.com'
  },
  {
    :name => '香港苹果家具厂',
    :link_phone => '1397611111',
    :link_man => '小庄',
    :address => '丘海大道11号',
    :email => 'a@gmail.com',
    :qq => '7888888',
    :msn => 'aa@hotmail.com'
  }
])

Material.create! [ {
    :code => 'XXX_1',
    :name => '红色布',
    :factory_id => Factory.first.id    
  },{
    :code => 'XXX_2',
    :name => '蓝色布',
    :factory_id => Factory.first.id
  },{
    :code => 'XXX_3',
    :name => '绿色布',
    :factory_id => Factory.first.id
  },{
    :code => 'XXX_4',
    :name => '黑色布',
    :factory_id => Factory.first.id
  }
]

FurnitureStyle.create! [ {
    :code => 'XXX_FU_1',
    :name => '真皮沙发',
    :factory_id => Factory.first.id
  },{
    :code => 'XXX_FU_2',
    :name => '餐桌椅',
    :factory_id => Factory.all[1].id
  },{
    :code => 'XXX_FU_3',
    :name => '衣柜',
    :factory_id => Factory.all[2].id
  },{
    :code => 'XXX_FU_4',
    :name => '餐桌',
    :factory_id => Factory.first.id
  }
]

Furniture.create! [ {
    :furniture_style_id => FurnitureStyle.first.id,
    :material_id => Material.first.id,
    :spec => '20x20x30'
  },{
    :furniture_style_id => FurnitureStyle.all[1].id,
    :material_id => Material.all[1].id,
    :spec => '20x20x10'
  },{
    :furniture_style_id => FurnitureStyle.all[2].id,
    :material_id => Material.all[2].id,
    :spec => '10x20x30'
  },{
    :furniture_style_id => FurnitureStyle.all[3].id,
    :material_id => Material.all[2].id,
    :spec => '100x20x30'
  }
]

FurnitureLogisticStat.create! [ {
    :dept_id => Dept::Storehouse.first.id,
    :furniture_id => Furniture.first.id,
    :entered_count => 20,
    :sold_count => 10,
    :ordered_count => 5
  },{
    :dept_id => Dept::Storehouse.all[1].id,
    :furniture_id => Furniture.first.id,
    :entered_count => 30,
    :sold_count => 10,
    :ordered_count => 5
  },{
    :dept_id => Dept::Storehouse.all[1].id,
    :furniture_id => Furniture.all[1].id,
    :entered_count => 10,
    :sold_count => 3,
    :ordered_count => 5
  },{
    :dept_id => Dept::Storehouse.all[2].id,
    :furniture_id => Furniture.all[1].id,
    :entered_count => 3,
    :sold_count => 1,
    :ordered_count => 2
  },{
    :dept_id => Dept::Storefront.all[2].id,
    :furniture_id => Furniture.all[2].id,
    :entered_count => 3,
    :sold_count => 1,
    :ordered_count => 2
  }
]

#Order.create! [{
#    :order_no => '2010121100011',
#    :buyer_id =>  Buyer.first.id,
#    :ordered_on => '2010-12-12',
#    :deliveried_on => '2010-12-12',
#    :saler_id => Employee.first.id,
#    :sale_price => 2000,
#    :order_price => 200,
#    :dept_id => Dept::Storefront.first.id,
#    :creator_id => Employee.first.id,
#    :status => 'being_edited'
#  }, {
#    :order_no => '2010121100012',
#    :buyer_id =>  Buyer.all[1].id,
#    :ordered_on => '2010-12-13',
#    :deliveried_on => '2010-12-13',
#    :saler_id => Employee.all[1].id,
#    :sale_price => 1000,
#    :order_price => 100,
#    :dept_id => Dept::Storefront.first.id,
#    :creator_id => Employee.first.id,
#    :status => 'being_edited'
#  }
#]
#
#OrderItem::FactoryOrderMade.create!( [{
#    :furniture_id => Furniture.first.id,
#    :order_id => Order.first.id,
#    :ordered_count => 30,
#    :has_been_sent_to_installer_count => 0,
#    :installed_count => 0,
#    :after_serviced_count => 0,
#    :remark => '靠枕要田园风格的'
#  },{
#    :furniture_id => Furniture.all[1].id,
#    :order_id => Order.first.id,
#    :ordered_count => 11,
#    :has_been_sent_to_installer_count => 0,
#    :installed_count => 0,
#    :after_serviced_count => 0,
#    :remark => '金属脚架'
#  },{
#    :furniture_id => Furniture.all[3].id,
#    :order_id => Order.first.id,
#    :ordered_count => 1,
#    :has_been_sent_to_installer_count => 0,
#    :installed_count => 0,
#    :after_serviced_count => 0,
#    :remark => '送抱枕'
#  }
#])
#
#OrderItem::SpotsOrdered.create! [{
#    :order_id => Order.first.id,
#    :ordered_count => 3,
#    :has_been_sent_to_installer_count => 0,
#    :installed_count => 0,
#    :after_serviced_count => 0,
#    :remark => '靠枕要田园风格的'
#  }
#]
#
#FurnitureLogisticStatOrderItem.create!([{
#    :furniture_logistic_stat_id => FurnitureLogisticStat.first.id,
#    :order_item_id => OrderItem::SpotsOrdered.first.id,
#    :ordered_count => 3
#  },{
#    :furniture_logistic_stat_id => FurnitureLogisticStat.all[1].id,
#    :order_item_id => OrderItem::SpotsOrdered.first.id,
#    :ordered_count => 4
#  }])
#
#Installation.create!( [ {
#    :install_no => '201112012',
#    :installed_on => '2010-11-12',
#    :should_be_payed_price => 200,
#    :payed_price =>  0,
#    :installer_id => Employee.first.id,
#    :creator_id => Employee.first.id,
#    :order_id => Order.first.id
#  }, {
#    :install_no => '2011120121',
#    :installed_on => '2011-11-12',
#    :should_be_payed_price => 8000,
#    :payed_price =>  0,
#    :installer_id => Employee.all[1].id,
#    :creator_id => Employee.all[1].id,
#    :order_id => Order.all[1].id
#  }
#])

OrderMade.create!([{
    :order_made_no => '20111112010101',
    :factory_id => Factory.first.id,
    :order_made_on => '2011-11-12',
    :order_made_price => 3000
  }
])

#OrderMadeItem.create!([{
#    :order_made_id => OrderMade.first.id,
#    :order_id => OrderItem::FactoryOrderMade.first.order_id,
#    :order_item_id => OrderItem::FactoryOrderMade.first.id,
#    :order_made_count => OrderItem::FactoryOrderMade.first.ordered_count,
#    :furniture_id => OrderItem::FactoryOrderMade.first.furniture_id
#  }
#])

FurnitureLogisticStat.all.each do |stat|
  OrderMadeItem.create!([{
      :order_made_id => OrderMade.first.id,
  #    :order_id => OrderItem::FactoryOrderMade.first.order_id,
  #    :order_item_id => OrderItem::FactoryOrderMade.first.id,
      :order_made_count => stat.entered_count,
      :furniture_id => stat.furniture_id
    }
  ])
end

FurnitureLogisticStat.all.each_with_index do |stat,index|
  EnterItem.create!(
    :order_made_id => OrderMadeItem.all[index].order_made_id,
    :order_made_item_id => OrderMadeItem.all[index].id,
    :furniture_id => stat.furniture_id,
    :furniture_logistic_stat_id => stat.id,
    :entered_on => '2011-12-12',
    :entered_count => stat.entered_count
  )
end